<?php
	
	/**
	 * Verifies bootstrapper execution to ensure file
	 * necessities, and disabling direct access
	 */
	defined('ENGINE') or exit;
	
	/**
	 * Error handler, this handles general errors from php. If 
	 * the script should error non fatal errors such as warnings 
	 * or notices, it will add them to the error buffer and show 
	 * then on the main template output. Note that this function is 
	 * not designed to be called directly and should be called by 
	 * php itself
	 */
	if(!function_exists('engine_error_handler'))
	{
		function engine_error_handler($level, $message, $file = NULL, $line = NULL, $variables = NULL)
		{
			if(!Engine::globals('error_reporting') || !(error_reporting() & $level))
			{
				return;
			}
			
			else if($level & E_RECOVERABLE_ERROR)
			{
				engine_doc_error('<strong>Recoverable error:</strong> ' . $message);
			}
			elseif($level & E_USER_ERROR)
			{
				engine_doc_error('<strong>Fatal error:</strong> ' . $message);
			}
			elseif($level & E_NOTICE || $level & E_USER_NOTICE)
			{
				$message = '<strong>Notice:</strong> ' . $message;
			}
			elseif(ENGINE_PHP_VERSION >= 50300 && ($level & E_DEPRECATED || $level & E_USER_DEPRECATED))
			{
				$message = '<strong>Deprecated:</strong> ' . $message;
			}
			elseif($level & E_STRICT)
			{
				$message = '<strong>Strict standards:</strong> ' . $message;
			}
			else
			{
				$message = '<strong>Warning:</strong> ' . $message;
			}
			
			if($level)
			{
				if(!is_null($file) && !is_null($line))
				{
					$message .= ' in ' . engine_trim_path($file) . ' on line ' . $line;
				}
			}
	
			if(!(Engine::globals('errors') instanceof ArrayObject))
			{
				Engine::globals('errors', new ArrayObject);
			}
	
			Engine::globals('errors')->append($message);
		}
	}

?>